<?php

namespace App\Console\Commands;

use App\Models\Service\Mqtt;
use Illuminate\Console\Command;

class MqttService extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'mqtt {action}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'mqtt 服务,用于设备通信 start|restart|stop|reload|status|connections';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        global $argv;
        $argv[1] = strtolower($argv[2]);
        unset($argv[2]);

        switch ($argv[1]) {
            case 'start':
            case 'restart':
            case 'stop':
            case 'reload':
            case 'status':
            case 'connections':
                Mqtt::on();
                break;
            default:
                $this->error('服务启动异常:' . $argv[1] . '是未定义服务命令');
                break;
        }
    }
}
